package baseObject;

public class Brick extends RectObj implements IBrick {
	private boolean breakeable;
	private int resistance;

	public Brick(int x, int y, int width, int height) {
		super(x, y, width, height);
		super.init(x, y, width, height);
	}

	public boolean isBreakable() {
		return this.breakeable;
	}

	public void setBreakeable(boolean breakeable){
		this.breakeable = breakeable;
	}


	public int getResistance() {
		return this.resistance;
	}


	public void hit() {
		if(this.isBreakable()){
			if(this.getResistance() > 0)
				this.setResistance(this.getResistance() - 1);
		}
	}


	public void setResistance(int r) {
		this.resistance = r;
	}

	public boolean equals(Object o){
		if(this == o)
			return true;
		else if(o.getClass() != this.getClass() || o == null)
			return false;
		else {
			IBrick autre = (IBrick) o;
			return (autre.getResistance() == this.getResistance() 
					&& autre.getHeight() == this.getHeight()
					&& autre.getWidth() == this.getWidth()
					&& autre.getX() == this.getX()
					&& autre.getY() == this.getY());
		}
	}
	
	@Override
	public Object cloneObj() {
		IBrick brick = new Brick(this.getX(), this.getY(), this.getWidth(), this.getHeight());
		brick.setResistance(this.getResistance());
		return brick;
	}

	@Override
	public boolean isOnTop(IRectObj ro) {
		if(ro.getX() > this.getX() && ro.getX() < this.getX() + this.getWidth()){
			if(ro.getY() > this.getY() && ro.getY() < this.getY() + this.getHeight()){
				return true;
			}
		}
		return false;
	}
}
